#ifndef SKINNEDMESH_H_
#define SKINNEDMESH_H_

#include <windows.h>
#include <d3dx9.h>
#include <string>
#include <vector>

struct BONE: public D3DXFRAME
{
	D3DXMATRIX CombinedTransformationMatrix;
};

struct BONEMESH: public D3DXMESHCONTAINER
{
	ID3DXMesh* OriginalMesh;
	std::vector<D3DMATERIAL9> m_vMaterials;
	std::vector<IDirect3DTexture9*> m_vTextures;

	DWORD NumAttributeGroups;
	D3DXATTRIBUTERANGE* attributeTable;
	D3DXMATRIX** boneMatrixPtrs;
	D3DXMATRIX* boneOffsetMatrices;
	D3DXMATRIX* currentBoneMatrices;

};

class CSkinnedMesh
{
private:
	IDirect3DDevice9* m_pDevice;
	D3DXFRAME* m_pRootBone;
	ID3DXAnimationController* m_pAnimControl;

	LPD3DXMESH m_pSphereMesh;

	//	Helper functions
	void UpdateMatrices(BONE* bone, D3DXMATRIX* parentMatrix);
	void SetupBoneMatrixPointers(BONE* bone);

public:
	CSkinnedMesh();
	~CSkinnedMesh();
	void Load(char* szFilename, IDirect3DDevice9* dev);
	void Render(BONE* bone);
	void RenderSkeleton(BONE* bone, BONE* parent, D3DXMATRIX world);

	void SetPose(D3DXMATRIX world, ID3DXAnimationController* animControl, float fTime);
	void SetAnimation(char* szName);
	std::vector<std::string> GetAnimations();
	BONE* FindBone(char* szName);

};
#endif